package com.java.basis.thread.pool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * newScheduledThreadPool
 * 创建一个定长线程池，支持定时及周期性任务执行。延迟执行示例代码如下：
 * @author wangning
 * @create 2021-04-25 21:50
 */
public class TestScheduledThreadPool01 {
	public static void main(String[] args) {
		//1.创建可定时线程池
		ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(5);
		for (int i = 0; i < 10; i++) {
			final int temp = i;
			newScheduledThreadPool.schedule(new Runnable() {
				public void run() {
					System.out.println("i:" + temp);
				}
			}, 3, TimeUnit.SECONDS);
		}

	}
}
